<template>
  <div class="page-container">
    <div class="page-top-bar">
      <div class="page-top-bar-wrap">
        <div class="page-top-bar-wrap-item-wrapper">
          <svg-icon class="bar-icon" icon="new-file" />
          <span class="bar-title">新建文件夹</span>
        </div>
      </div>
      <div class="page-top-bar-wrap">
        <div class="page-top-bar-wrap-item-wrapper">
          <svg-icon class="bar-icon" icon="delete-manage" />
          <span class="bar-title">删除文件夹</span>
        </div>
      </div>
      <div class="page-top-bar-wrap">
        <div class="page-top-bar-wrap-item-wrapper">
          <svg-icon class="bar-icon" icon="upload-file" />
          <span class="bar-title">上传文件</span>
        </div>
      </div>
    </div>
    <div class="upload-manage">
      <div class="folder-content">
        <div
          class="folder"
          :class="{ active: selectFolder == index }"
          v-for="(item, index) in folder"
          :key="index"
          @click="select(item, index)"
        >
          <span>{{ item.name }}</span>
        </div>
      </div>
      <div class="file-content">
        <div class="file-list">
          <div
            class="file-item"
            v-for="(item, index) in urls"
            :key="index"
            @click="checked(item, index)"
          >
            <div class="file">
              <div class="focus-container">
                <span class="focus" v-if="isSelect" @click="selectImg(item)">
                  <svg-icon class="focus-icon" icon="select" />
                </span>
                <span class="focus">
                  <svg-icon class="focus-icon" icon="delete" />
                </span>
              </div>
              <el-image :src="item" lazy></el-image>
              <!-- <img :src="item" alt="item" /> -->
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    url: {
      type: String,
      required: false
    },
    isSelect: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      selectFolder: 0,
      imgIndex: null,
      folder: [
        {
          id: 1,
          name: "视频文件夹",
        },
        {
          id: 2,
          name: "图片",
        },
      ],
      urls: [
        "https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg",
        "https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg",
        "https://fuss10.elemecdn.com/0/6f/e35ff375812e6b0020b6b4e8f9583jpeg.jpeg",
        "https://fuss10.elemecdn.com/9/bb/e27858e973f5d7d3904835f46abbdjpeg.jpeg",
        "https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg",
        "https://fuss10.elemecdn.com/3/28/bbf893f792f03a54408b3b7a7ebf0jpeg.jpeg",
        "https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg",
        "https://fuss10.elemecdn.com/0/6f/e35ff375812e6b0020b6b4e8f9583jpeg.jpeg",
        "https://fuss10.elemecdn.com/9/bb/e27858e973f5d7d3904835f46abbdjpeg.jpeg",
        "https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg",
        "https://fuss10.elemecdn.com/2/11/6535bcfb26e4c79b48ddde44f4b6fjpeg.jpeg",
        "https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg",
        "https://fuss10.elemecdn.com/0/6f/e35ff375812e6b0020b6b4e8f9583jpeg.jpeg",
        "https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg",
        "https://fuss10.elemecdn.com/0/6f/e35ff375812e6b0020b6b4e8f9583jpeg.jpeg",
        "https://fuss10.elemecdn.com/9/bb/e27858e973f5d7d3904835f46abbdjpeg.jpeg",
        "https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg",
        "https://fuss10.elemecdn.com/9/bb/e27858e973f5d7d3904835f46abbdjpeg.jpeg",
        "https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg",
      ],
    };
  },
  methods: {
    selectImg(data){
      this.$emit("selectImg", data);
    },
    select(data, index) {
      this.selectFolder = index;
    },
    checked(data, index) {
      this.imgIndex = index;
    },
  },
};
</script>

<style lang="scss" scoped>
.upload-manage {
  width: 100%;
  height: calc(100% - 56px);
  display: flex;
  justify-content: space-between;
}

.folder-content {
  width: 210px;
  height: 100%;
  margin-right: 10px;

  .folder {
    width: 100%;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-sizing: border-box;
    border-left: 4px solid var(--background-hover);
    color: var(--color);
  }

  .active {
    border-left: 4px solid #409eff;
    background-color: var(--background-hover);
  }
}

.file-content {
  flex: 1;
  height: 100%;
  overflow: hidden;
  overflow-y: auto;

  .file-list {
    width: 100%;
    height: 100px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
  }

  .file-item {
    position: relative;
    width: 25%;
    padding: 4px;
    padding-top: 0px;
    text-align: center;
    box-sizing: border-box;
    margin-bottom: 4px;

    .checked {
      position: absolute;
      top: 4px;
      left: 8px;
      width: 18px;
      height: 18px;
      background: #409eff;
      z-index: 1024;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 50%;

      & span {
        display: block;
        width: 8px;
        height: 8px;
        background: #fff;
        border-radius: 50%;
      }
    }

    .file {
      position: relative;
      width: 100%;
      height: 100%;
      border-radius: 2px;
      overflow: hidden;
      display: flex;
      align-items: center;
      cursor: pointer;

      .focus-container {
        position: absolute;
        width: 100%;
        height: 100%;
        opacity: 0;
        transform: translateX(-100%);
        transition: all 0.28s ease-in;
      }

      .focus {
        color: #fff;
        margin: 0 10px;

        &:hover {
          color: #409eff;
        }
      }

      .focus-icon {
        width: 24px;
        height: 24px;
      }

      &:hover {
        .focus-container {
          transform: translateX(0%);
          opacity: 1;
          z-index: 12;
          display: flex;
          justify-content: center;
          align-items: center;
          color: #fff;
          background: #0404045f;
        }

        img {
          scale: 1.2;
        }
      }

      & img {
        width: 100%;
        transition: all 0.58s ease;
      }
    }
  }
}

.upload-push-button {
  width: 100%;
  background: #f4f4f4;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
}

.page-top-bar {
  width: 100%;
  display: flex;
  justify-content: flex-start;
  margin-bottom: 16px;

  .page-top-bar-wrap {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    padding: 0 10px;
    height: 32px;
    margin-right: 16px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    transition: background 0.15s ease-out, border 0.15s ease-out;

    .page-top-bar-wrap-item-wrapper {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      color: var(--font-hover);
    }

    .bar-icon {
      width: 20px;
      height: 20px;
    }

    .bar-title {
      margin: 0 8px;
      font-size: 14px;
    }

    &:hover {
      background-color: var(--background-hover);
      border-color: var(--border-color);
      cursor: pointer;
    }
  }
}

.file-manage {
  width: 100%;
  display: flex;
  justify-content: flex-start;
}
</style>